/*
 * @Description: 车主注册 AuthenticationAudit
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-23 11:56:13
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-12-07 13:48:52
 */
import 'package:city_pickers/city_pickers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/provider/position_information.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/widget/spinkit.dart';
import 'package:provider/provider.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/widget/bottom_sheet_widget.dart';

class AuthenticationAudit extends StatefulWidget {
  final String type;
  AuthenticationAudit({this.type});
  @override
  _AuthenticationAuditState createState() => _AuthenticationAuditState();
}

class _AuthenticationAuditState extends State<AuthenticationAudit> {
  WidgetsBinding widgetsBinding = WidgetsBinding.instance;

  /// 选择车主加入方式
  List<Map> _accessionMode = [
    {'name': '自己带车入驻', 'num': '1'},
    {'name': '租车入驻', 'num': '2'},
  ];
  String _selectAccessionMode = '自己带车入驻';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('车主注册'),
        elevation: 0,
      ),
      resizeToAvoidBottomPadding: false, //输入框抵住键盘
      body: Container(
        padding: EdgeInsets.all(ScreenUtil().setWidth(30.0)),
        color: Color(0xffFFFFFF),
        child: FutureBuilder(
            future: Request.getDriverFeeState(),
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              if (snapshot.hasData) {
                var dataInfo = snapshot.data;
                return Column(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        child: Column(
                          children: <Widget>[
                            Container(
                              alignment: Alignment.topLeft,
                              child: Text(
                                '信息仅用于认证审核，绝不外泄',
                                style: TextStyle(
                                  fontSize: ScreenUtil().setSp(28.0),
                                  color: Color(0xff3FB956),
                                ),
                              ),
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            InkWell(
                              child: Consumer<PositionInformation>(
                                  builder: (ctx, state, child) {
                                return _dataList(
                                  '城市选择',
                                  '${state.driverCurrentCity}',
                                );
                              }),
                              onTap: () async {
                                Result result2 =
                                    await CityPickers.showFullPageCityPicker(
                                  context: context,
                                );
                                Provider.of<PositionInformation>(context,
                                        listen: false)
                                    .setCityName(result2.areaName);
                              },
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            InkWell(
                              child: _dataList(
                                '加入方式',
                                _selectAccessionMode,
                              ),
                              onTap: () async {
                                await openModalBottomSheet(context, '选择加入方式',
                                        _accessionMode, _selectAccessionMode)
                                    .then((res) {
                                  if (res != null) {
                                    Provider.of<DriverInformation>(context,
                                            listen: false)
                                        .setAccessionMode(res);
                                    setState(() {
                                      _selectAccessionMode = res;
                                    });
                                  }
                                });
                              },
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            InkWell(
                              child: Consumer<DriverInformation>(
                                  builder: (context, state, child) {
                                return _dataList('身份证与驾驶证', '',
                                    perfectState:
                                        state.driverInfo.idCardUploadState !=
                                                null
                                            ? state.driverInfo.idCardUploadState
                                            : false);
                              }),
                              onTap: () =>
                                  NavigatorUtil.jump(context, '/uploadIdCard'),
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            InkWell(
                              child: Consumer<DriverInformation>(
                                  builder: (context, state, child) {
                                return _dataList('行驶证与车辆', '',
                                    perfectState: state.driverInfo
                                                .drivingUploadState !=
                                            null
                                        ? state.driverInfo.drivingUploadState
                                        : false);
                              }),
                              onTap: () => NavigatorUtil.jump(
                                  context, '/drivingLicenseVehicle'),
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            Offstage(
                              offstage: widget.type != '0010',
                              child: InkWell(
                                child: Consumer<DriverInformation>(
                                    builder: (context, state, child) {
                                  return _dataList('网约车驾驶证与车辆营运证', '',
                                      perfectState: state.driverInfo
                                                  .qualificationCertificateState !=
                                              null
                                          ? state.driverInfo
                                              .qualificationCertificateState
                                          : false);
                                }),
                                onTap: () => NavigatorUtil.jump(
                                    context, '/professionalQualification'),
                              ),
                            ),
                            SizedBox(height: ScreenUtil().setWidth(20.0)),
                            // _franchiseFee(dataInfo['driver_fee'].toString(), dataInfo['fee_state']),
                          ],
                        ),
                      ),
                    ),
                    MaterialButton(
                      color: Color(0xff3FB956),
                      minWidth: ScreenUtil().setWidth(700.0),
                      height: ScreenUtil().setWidth(100.0),
                      textColor: Colors.white,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(50)))),
                      child: Text(
                        '去审核车主',
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(32.0),
                            fontWeight: FontWeight.w500),
                      ),
                      onPressed: () =>
                          Request.goToCheckOwner(context, widget.type),
                    ),
                    SizedBox(height: ScreenUtil().setWidth(50.0)),
                  ],
                );
              } else {
                return Spinkit();
              }
            }),
      ),
    );
  }

  Widget _dataList(title, describe, {bool perfectState}) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(
            width: ScreenUtil().setWidth(1),
            color: Color(0xffeeeeee),
          ),
        ),
      ),
      width: ScreenUtil().setWidth(710.0),
      height: ScreenUtil().setWidth(100.0),
      padding: EdgeInsets.only(left: ScreenUtil().setWidth(20.0)),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(
              title,
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: ScreenUtil().setSp(30),
              ),
            ),
          ),
          Row(
            children: <Widget>[
              Offstage(
                offstage: perfectState == null || !perfectState,
                child: Text('已上传', style: TextStyle(color: Color(0xff333333))),
              ),
              Offstage(
                offstage: perfectState == null || perfectState,
                child: Text('未上传', style: TextStyle(color: Color(0xff3FB956))),
              ),
              SizedBox(width: ScreenUtil().setWidth(20.0)),
              Text(
                describe,
                textAlign: TextAlign.right,
                style: TextStyle(
                  color: Color(0xff333333),
                  fontSize: ScreenUtil().setSp(30),
                ),
              ),
              Icon(
                Icons.chevron_right,
                size: ScreenUtil().setWidth(35.0),
                color: Colors.black26,
              )
            ],
          ),
        ],
      ),
    );
  }

  /// 平台管理费
  Widget _franchiseFee(String money, String feeState) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(6.0)),
      ),
      width: ScreenUtil().setWidth(710.0),
      height: ScreenUtil().setWidth(100.0),
      padding: EdgeInsets.only(left: ScreenUtil().setWidth(20.0)),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text('平台管理费'),
          ),
          Container(
              margin: EdgeInsets.only(right: ScreenUtil().setWidth(20.0)),
              child: Row(
                children: <Widget>[
                  Text(
                    '¥$money',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(35.0),
                      fontWeight: FontWeight.w700,
                      color: Color.fromARGB(255, 255, 153, 0),
                    ),
                  ),
                  SizedBox(width: ScreenUtil().setWidth(30.0)),
                  Stack(
                    children: <Widget>[
                      Offstage(
                        offstage: feeState != '0000',
                        child: Text(
                          '已缴费',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(30.0),
                            color: Colors.green,
                          ),
                        ),
                      ),
                      Offstage(
                        offstage: feeState != '0010',
                        child: Text(
                          '未缴费',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(30.0),
                            color: Color.fromARGB(255, 255, 153, 0),
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              )),
        ],
      ),
    );
  }
}
